Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
www
/
admin
/
app
/
Models
/
Filename :
User.php
back
Copy
<?php namespace App\Models; use App\Models\SchoolManagement\StudentSegment; use App\Models\SchoolManagement\StudentSegmentUser; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; use App\Models\UserSetting; use Illuminate\Database\Eloquent\Casts\Attribute; use Config; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOne; use Laratrust\Traits\LaratrustUserTrait; class User extends Authenticatable { use LaratrustUserTrait; use SoftDeletes; protected $table = 'users'; protected $primaryKey = 'user_id'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'user_id', 'uuid', 'full_name', 'username', 'email', 'mobile', 'profile_pic', 'password', 'coins_for_college_role_id', 'otp', 'facebook_id', 'google_id', 'apple_id', 'api_token', 'device_type', 'device_token', 'is_email_verified', 'active_group_id', 'is_active', 'ios_notify_invite_done', 'android_notify_invite_done', 'preferred_college_id', 'preferred_school_id', 'created_by_type', 'created_by_id', 'created_at', 'updated_at', 'deleted_at' ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'deleted_at' ]; protected function profilePic(): Attribute { return Attribute::make( get: fn (string $value) => Config::get('constants.app.api-profile-pic-url').$value, ); } public function cfcRole(): HasOne{ return $this->hasOne(CoinsForCollegeRole::class, 'coins_for_college_role_id', 'coins_for_college_role_id'); } public function setting() : HasOne { return $this->hasOne('App\Models\UserSetting', 'user_id'); } public function userAddress(): HasOne{ return $this->hasOne(UserAddress::class, 'user_id', 'user_id'); } public function preferredCollege(): HasOne{ return $this->hasOne(College::class, 'college_id', 'preferred_college_id'); } public function preferredSchool(): HasOne{ return $this->hasOne(School::class, 'school_id', 'preferred_school_id'); } public function membershipGroups(): HasManyThrough{ $queryObject = $this->hasManyThrough( 'App\Models\Group','App\Models\GroupMember', 'member_user_id', 'group_id', 'user_id', 'group_id') ->where('group_members.invitation_accepted', 1); return $queryObject; } public function owningGroups(): HasMany{ return $this->hasMany(Group::class, 'owner_user_id', 'user_id'); } public function getNameAttribute(){ return $this->full_name; } //additional parameters //stores 'CHILD','PARENT','SOCIAL_WORKER' private $currentRole; private $currentTeam; private $currentGroup; public function populateTeamAndRole(Group $currentGroup){ $this->currentGroup = $currentGroup; $this->currentTeam = $this->currentGroup->team; if($this->currentTeam != null){ // $this->currentRole = $this->rolesTeams()->where('name',$this->currentTeam->name)->first(); $roles = $this->getRoles($this->currentTeam); if(count($roles) > 0){ $this->currentRole = $roles[0]; } } } public function getCurrentRole(){ return $this->currentRole; } public function getCurrentTeam(){ return $this->currentTeam; } public function getCurrentGroup(){ return $this->currentGroup; } public function claims(): HasMany{ return $this->hasMany('App\Models\AllClaim', 'claimed_by_user_id', 'user_id'); } public function studentSegments($schoolId = null) { return $this->belongsToMany( StudentSegment::class, 'student_segment_user', 'user_id', 'student_segment_id' ) ->using(StudentSegmentUser::class) // Ensure pivot model is used ->withTimestamps() ->whereNull('student_segments.deleted_at') // Ensure segments are not soft-deleted ->wherePivotNull('deleted_at') // Ensure pivot entries are not soft-deleted ->when($schoolId, function ($query) use ($schoolId) { $query->where('student_segments.school_id', $schoolId); }) ->wherePivot('user_id', $this->user_id); // Ensure filtering by user_id } }